package com.pet.server.ext.action.timeline;

import java.util.List;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Image;
import com.pet.server.ext.data.Page;
import com.pet.server.ext.data.PetMissing;
import com.pet.server.ext.data.TimeLine;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;

public class Query extends ActionBase{

	public Integer startIndex,itemCount,pet_id;
	public String queryString;
	public Page page;
	public Query(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		parseToParameter(params);
		pet_id=NumberUtil.getInteger(params.getFieldValue("pet_id"));
		itemCount = p.itemCount==0?10:p.itemCount;
		page = new Page(p.startIndex, itemCount,p.queryString);
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		userService.searchTimeLine(page, user.user_id, pet_id);
		
		for(TimeLine ti:(List<TimeLine>)page.getList()){
            List<Image> l = userService.queryImage(ti.id, BaseAttribute.image_type.time_line.toString());
            ti.list=l;
		}
		Result result = new Result();
        result.setPage(page,"oid","pet_id","type");
	    return result;
	}


}
